The idea is that two capacitors are joined. Initially C_1 has a p.d. of 10 V and C_2 has zero. All constants can be changed.


In [21]:
C1 = 1e-6 # 1 micro-farad
V1 = 1000
Q1 = C1 * V1
E1 = 0.5*Q1*V1
E2 = 0.5*Q2*V2
E_start = 0.5*Q1*C1 + 0.5*Q2*C2
E_loss = 0
I = 0 # amps
R = 1000 # ohms
dt = 1e-6 # seconds

In [26]:
while(True):
    I = (V1-V2)/R
    ## Now, allow a small amount of charge to flow around the circuit
    dQ = I*dt
    Q1 -= dQ
    Q2 += dQ
    E_loss += I**2 * R * dt # energy loss in resistor
    E1 -= V1 * dQ
    E2 += V2 * dQ
    ## Now, calculate new voltages
    V1 = Q1 / C1
    V2 = Q2 / C2
    print(I)
    if I < 1e-5:
        break

E_final = 0.5*Q1*C1 + 0.5*Q2*C2


9.964651326299644e-14

In [27]:
I = (V1-V2)/R

In [ ]: